/**
 * 实现手势密码作为数字数组和数字之间的转化 (为了存入本地数据库)
 */

export class PasswordHandler {
  /**
   * 把数组转化为数字
   * @param password
   */
  public toNumber(password: number[]) {
    let password2: number = 0;
    for (let i: number = 0; i < password.length; i++) {
      password2 = password2 * 10 + password[i];
    }
    return password2;
  }

  /**
   * 把数字转化为数组
   * @param password
   */
  public toArray(password: number) {
    let array: Array<number> = new Array();
    let x: number = password;
    for (;; ) {
      //不限number长度
      if (x >= 0 && x >= 9) {
        array.push(x);
        break;
      }
      let temp: number = x % 10
      array.push(temp);
      x /= 10;
      x -= 0.1 * (temp);
    }
    array.reverse();
    return array;
  }
}